import React from "react";
import { Route, Switch, Redirect, withRouter } from "react-router-dom";
import pubsub from 'pubsub-js';
// import Header from '../components/header'
import Footer from '../components/footer'
import Home from '../pages/home'
import UcLoading from '../components/uc-loading/uc-loading'
import Follow from "../pages/follow";
import Column from "../pages/column";
import User from "../pages/user/index"
import Login from "../pages/login/login"
import Reg from "../pages/reg/reg";
import Detail from "../pages/detail";
// 插件库
import NavTabs from "../components/Nav_Tabs/index";
import NavHeade from '../components/Nav_header';

class Default extends React.Component {

    constructor() {
        super();
        this.token = pubsub.subscribe('update_loading', (msg, bl) => {
            this.setState({ bLoading: bl })
        });
    }
    state = {
        bNav: true,
        bFoot: true,
        bLoading: true
    };
    async componentDidMount() {
    }
    static getDerivedStateFromProps(nextProps, nextState) {
        let path = nextProps.location.pathname;
        if (/home|follow|column/.test(path)) {
            return {
                bNav: true,
                bFoot: true,
            }
        }
        if (/login|reg|detail/.test(path)) {
            return {
                bNav: false,
                bFoot: false,
                bLoading: false
            }
        }
        if (/user/.test(path)) {
            return {
                bNav: false,
                bFoot: true,
            }
        }
        if (/colUmn/.test(path)) {
            return {
                bNav: true,
                bFoot: true
            }
        }
        return null;
    }
    render() {
        return (
            <div>
                <UcLoading spinning={this.state.bLoading} />
                {/* {this.state.bNav && <Header />} */}
                {this.state.bNav && <NavHeade /> && <NavTabs />}
                <Switch>
                    <Route path="/detail" component={Detail} />
                    <Route path="/reg" component={Reg} />
                    <Route path="/login" component={Login} />
                    <Route path="/user" component={User} />
                    <Route path="/footer" component={Footer} />
                    <Route path="/home" component={Home} />
                    {/* <Route path="/header" component={Header} /> */}
                    {/* 插件库-导航栏 */}
                    <Route path="/Nav_header" component={NavHeade} />
                    <Route path="/follow" component={Follow} />
                    <Route path="/column" component={Column} />
                    <Redirect from='/' to='/home' exact={true} />
                </Switch>
                {this.state.bFoot && <Footer />}
            </div>
        )
    }
}
export default withRouter(Default)